//
//  LXLocationAction+AnalyseHelper.m
//  LXLocationRelated
//
//  Created by Livespro on 2017/10/22.
//  Copyright © 2017年 Livesxu. All rights reserved.
//

#import "LXLocationAction+AnalyseHelper.h"
#import "LXHandleDatas.h"

@implementation LXLocationAction (AnalyseHelper)

- (void)analyseLocation:(CLLocation *)location Heading:(CLHeading *)newHeading;{
    
    //水平海拔，速度，航向，负值不可用
    if (location.horizontalAccuracy < 0 || location.speed < 0 || location.course < 0) {
        return;
    }
    if (!self.isManual) {//非手动开始
        
#pragma mark - 标记判断 开始运动 - 起步判断
        if (!self.isRun) {//不在记录中 - 开始运动 ->
            
            //速度低于.5,不记录
            if (location.speed < .5f) {
                return;
            }
            
            self.isRun = YES;
            
            [[LXHandleDatas shareHandle] handleDistanceIn:location];
            
        }
        
        [[LXHandleDatas shareHandle] handleLocationInfoLatitude:location.coordinate.latitude longitude:location.coordinate.longitude altitude:location.altitude horizontalAccuracy:location.horizontalAccuracy verticalAccuracy:location.verticalAccuracy course:location.course speed:location.speed timestamp:location.timestamp trueHeading:newHeading.trueHeading headingAccuracy:newHeading.headingAccuracy];
        
        self.speedGradient = location.speed / kAnalyseSpeedForDistanceFilter;
        
#pragma mark - 标记判断 结束运动 - 停止判断
        if (self.isRun) {
            
            //速度大于.1,继续行驶
            if (location.speed > .1f) {
                return;
            }
            
            self.isRun = NO;
            
            [[LXHandleDatas shareHandle] handleDistanceEnd:location];
        }
        
    }else{//手动开始
        
        if (!self.isRun) {//标记运动
            
            self.isRun = YES;
            
            [[LXHandleDatas shareHandle] handleDistanceIn:location];
            
        }
        
        [[LXHandleDatas shareHandle] handleLocationInfoLatitude:location.coordinate.latitude longitude:location.coordinate.longitude altitude:location.altitude horizontalAccuracy:location.horizontalAccuracy verticalAccuracy:location.verticalAccuracy course:location.course speed:location.speed timestamp:location.timestamp trueHeading:newHeading.trueHeading headingAccuracy:newHeading.headingAccuracy];
        
        self.speedGradient = location.speed / kAnalyseSpeedForDistanceFilter;
    }
}

/**
 优化定位配置 ||
 */
- (void)optimizeLocations;{
    
    
}

- (void)setSpeedGradient:(NSInteger)speedGradient{
    
    self.locationM.distanceFilter = (speedGradient +1) * kLocationDistanceFilter;
    
    [[LXHandleDatas shareHandle] handleMonitorIn:[NSString stringWithFormat:@"定位变更通知距离%.0f - %@%@",self.locationM.distanceFilter,NSStringFromClass([self class]),NSStringFromSelector(_cmd)] Time:[NSDate date] User:@"01"];
}

@end
